package com.wangjiacai.hql.condition.where;

import com.wangjiacai.hql.condition.Condition;
import com.wangjiacai.util.HqlUtil;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Condition(condition = Less.LessCondition.class,column = Less.LessCondition.class)
public @interface Less {

    String column() default "";

    String hql() default "";

    class LessCondition implements Condition.Where<Less,Object>, Condition.Column<Less> {
        @Override
        public String where(Less less,String property,String column,Object obj,Object value) {
            return less.hql().equals("")?column+" < :"+property:column+" < ("+ HqlUtil.parseHql(less.hql(),obj)+")";
        }

        @Override
        public String column(Less less, String property) {
            return less.column().equals("")?property:less.column();
        }
    }

}
